package com.sren.initializrstart.service.impl;

import com.sren.initializrstart.service.CityDataService;
import com.sren.initializrstart.util.XmlBuilder;
import com.sren.initializrstart.vo.City;
import com.sren.initializrstart.vo.CityList;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.List;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Service;

/**
 * @author sren
 * @create 2018-12-10 上午9:14
 **/

@Service
public class CityDataServiceImpl implements CityDataService {

    @Override
    public List<City> listCity() throws Exception {
        Resource resource = new ClassPathResource("city.xml");
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(resource.getInputStream(), "utf-8"));
        StringBuffer stringBuffer = new StringBuffer();
        String line = "";
        while ((line = bufferedReader.readLine()) != null) {
            stringBuffer.append(line);
        }
        bufferedReader.close();
        CityList cityList = (CityList) XmlBuilder.xml2Obj(CityList.class, stringBuffer.toString());
        return cityList.getCityList();
    }
}
